import {createRouter,createWebHashHistory} from 'vue-router'

const router =createRouter({
    history:createWebHashHistory(),
    routes:[
        {
            path:'/',
            component:()=>import('../views/home/Home.vue')
        },
        {
            path:'/cart',
            component:()=>import('../views/cart/cart.vue'),
            meta:{
                isAuth:true
            }
        },
        {
            path:'/home',
            component:()=>import('../views/home/Home.vue')
        },
        {
            path:'/my',
            component:()=>import('../views/my/My.vue'),
            meta:{
                isAuth:true
            }
        },
        {
            path:'/order',
            component:()=>import('../views/order/Order.vue'),
            meta:{
                isAuth:true
            }
        },
        {
            path:'/login',
            component:()=>import('../views/Login/login.vue')
        },
        {
            path:'/register',
            component:()=>import('../views/register/Register.vue')
        },
        {
            path: '/address',
            component:()=>import('../views/address/Address.vue')
        },
        {
            path:'/userlnfoEdit',
            component:()=>import('../views/userlnfoEdit/UserlnfoEdit.vue')
        },
        {
            path:'/UserlnfoList',
            component:()=>import('../views/userlnfoEdit/UserlnfoList.vue')
        }
    ]
})

router.beforeEach((to,from,next)=>{
    if(to.meta.isAuth){
        if(localStorage.getItem('isLogin')==='1'){
            next()
        }else{
            alert('请先登录')
            router.push('./login')
        }
    }else{
        next()
    }
})

export default router